﻿using Md.Api.Entity.DapperModels.MdDB;
using Md.Api.Model.Manage.MdProductExperience.Request;
using Md.Dapper.Repositories.Md;

namespace Md.Api.Service.Manage.MdProductExperience;
/// <summary>
/// 添加体验产品关联服务
/// </summary>
public class InsertMdProductExperienceService : ApiBase<RequestInsertMdProductExperienceModel>
{
    /// <summary>
    /// 体验产品关联仓储
    /// </summary>
    public MdProductExperienceRep mdProductExperienceRep { get; set; }
    /// <summary>
    /// 执行
    /// </summary>
    protected override void ExecuteMethod()
    {
        // 先删除关联数据
        var list = mdProductExperienceRep.GetMdProductExperienceIdsByProductId(Parameter.ProductId);

        if (list.Count() > 0)
        {
            mdProductExperienceRep.DeleteMdProductExperienceByProductId(Parameter.ProductId);
        }

        // 重新增加关联数据
        var model = new MdProductExperienceModel();

        model.ProductId = Parameter.ProductId;
        model.ExperienceId = Parameter.ExperienceId;

        var res = mdProductExperienceRep.Insert(model);

        Result.Data = res;
    }
}
